using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace InventorySystem
{
    public class ItemCollisionHandler : MonoBehaviour
    {
        private Inventory _inventory;
        private void Awake()
        {
            _inventory = GetComponentInParent<Inventory>();
        }
        private void OnTriggerEnter2D(Collider2D col)
        {
            // 检测碰撞的对象是否拥有 GameItem 组件
            var gameItem = col.GetComponent<GameItem>();
            // if (gameItem == null) return;
            // gameItem.Pick();
            if (gameItem == null || !_inventory.CanAcceptItem(gameItem.Stack)) return;
            _inventory.AddItem(gameItem.Pick());
        }

    }
}
